package com.mf.controller;

import com.mf.dto.MACD.MACDDto;
import com.mf.entity.RecommendCode;
import com.mf.service.code.ICodeService;
import com.mf.service.IRecommendCodeService;
import com.mf.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 股票推荐表 前端控制器
 * </p>
 *
 * @author mf
 * @since 2024-05-01
 */
@RestController
@RequestMapping("/stock/recommendCode")
@Tag(name = "股票推荐表")
public class RecommendCodeController {
    @Resource
    private IRecommendCodeService recommendCodeService;

    @Resource
    private ICodeService codeService;

    @PostMapping("/addHistoricalData")
    @Operation(summary ="根据股票代码新增历史数据")
    public Result<Boolean> addRecommendCode(@RequestBody MACDDto macdDto)
    {
        recommendCodeService.remove(null);
        final List<RecommendCode> historicalData = codeService.findHistoricalData(macdDto);
        if (!historicalData.isEmpty())
        {
            recommendCodeService.saveBatch(historicalData,500);
        }
        return Result.success(true);
    }
}
